package com.aphrodite.ui.widgets;

import javax.microedition.lcdui.CustomItem;
import javax.microedition.lcdui.Graphics;

import com.aphrodite.ui.graphics.GraphicUtil;

/**
 * rendering helper methods
 * 
 * @author kentelt
 * 
 */
public final class WidgetHelper {

	/**
	 * Check if the given point is in the widget
	 * 
	 * 
	 * @param widget
	 *            to perform check on
	 * @param x
	 *            coordinate
	 * @param y
	 *            coordinate
	 * @return true if the point is in the widget. Returns false if the point is
	 *         in the title of the widget
	 */
	static boolean isPointInWidget(Widget widget, int x, int y) {
		return false;
	}

	final static int radioBtnHeight = 14;
	final static int checkBoxHeight = 14;
	final static int arrowWidth = 10;
	final static int arrowHeight = (arrowWidth / 2) + 1;

	/**
	 * 
	 * @param g
	 * @param x
	 *            point of radius
	 * @param y
	 *            point of radius
	 * @param isSelected
	 *            is the button selected.
	 */
	static void drawRadio(final Graphics g, int x, int y, boolean isSelected) {
		x += 7;

		g.setColor(Theme.baseCmpColor);
		GraphicUtil.drawCircle(g, x, y, radioBtnHeight);
		if (isSelected) {
			GraphicUtil.fillCircle(g, x, y, radioBtnHeight / 2);
		}
	}

	/**
	 * 
	 */
	static void drawCheck(final Graphics g, int x, int y, boolean isSelected) {
		g.setColor(Theme.baseCmpColor);
		g.drawRoundRect(x, y, checkBoxHeight, checkBoxHeight, 3, 3);
		if (isSelected) {
			/* draw tick */
			g.drawLine(x + 7, y + 10, x + checkBoxHeight, y - 2);
			g.drawLine(x + 7, y + 9, x + 13, y - 1);

			g.drawLine(x + 7, y + 10, x + 2, y + 6);
			g.drawLine(x + 7, y + 9, x + 2, y + 6);
		}
	}

	/**
	 * Draw spinner/combo box arrows
	 * 
	 * @param g
	 *            Graphics context
	 * @param x
	 *            coordinate of the arrow
	 * @param y
	 *            coordinate of the arrow
	 * @param direction
	 *            Custom item layout direction
	 */
	public static void drawSpinnerArrows(final Graphics g, int x, int y, final int direction) {
		g.setColor(Theme.baseCmpColor);
		if (direction == CustomItem.LAYOUT_BOTTOM || direction == CustomItem.LAYOUT_TOP) {
			for (int i = 0; i < arrowHeight; i++) {
				g.drawLine(x + i, y, x + arrowWidth - i, y);
				y = (direction == CustomItem.LAYOUT_BOTTOM) ? y + 1 : y - 1;
			}
		} else {
			for (int i = 0; i < arrowHeight; i++) {
				g.drawLine(x, y + i, x, y + arrowWidth - i);
				x = direction == CustomItem.LAYOUT_RIGHT ? x + 1 : x - 1;
			}
		}
	}
}
